<template>
  <div class="mod-config">
    <basic-container>
      <navigation :sign="{a:true,b:false,c:false,d:false,e:false}"></navigation>
      <div class="boxsty zhiBiao">
        <div class="flex justifyContentSpaceBetween">
          <div class="tabletext">机构得分维护</div>
          <div class="tablelink">
            <!--<el-button v-if="permissions.jiangjin_jiangjinjgdfb_add" icon="el-icon-plus" type="primary" @click="addOrUpdateHandle()">新增</el-button>-->
          </div>
        </div>
        <el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()" class="form-inline">
          <el-form-item label="选择年度">
            <el-select v-model="dataForm.year" placeholder="请选择">
              <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item>
            <el-button icon="el-icon-search" type="primary" class="marginLeft" plain @click="getDataList()">检索</el-button>
            <el-button icon="el-icon-plus" type="primary" class="marginLeft" >数据同步</el-button>
          </el-form-item>
        </el-form>
        <span>&nbsp;
        <el-button v-if="permissions.jiangjin_jiangjinjgdfb_edit" type="primary" plain size="small">表格导入</el-button>
        <el-button v-if="permissions.jiangjin_jiangjinjgdfb_edit" type="primary" plain size="small">表格导出</el-button>
        </span>
        <div>&nbsp;</div>
        <div class="avue-crud" style="max-height:calc(100vh - 370px)">
          <el-table :data="dataList" border v-loading="dataListLoading">
            <el-table-column prop="" label="序号" header-align="center" align="center" :formatter="nShowIndex" width="70"></el-table-column>
            <el-table-column prop="lxDeptName" header-align="center" align="center" label="部门名称" width="150"></el-table-column>
            <el-table-column prop="lxUserName" header-align="center" align="center" label="姓名" width="100"></el-table-column>
            <el-table-column prop="lxUserZw" header-align="center" align="center" label="职务" width="180"></el-table-column>
            <el-table-column prop="yearDf" header-align="center" align="center" label="年度得分" width="100"></el-table-column>
            <el-table-column prop="yearJd" header-align="center" align="center" label="考核结果" width="100"></el-table-column>
            <el-table-column prop="lxXs" header-align="center" align="center" label="预留系数" width="100"></el-table-column>
            <el-table-column header-align="center" align="center" label="操作">
              <template slot-scope="scope">
                <el-button v-if="permissions.jiangjin_jiangjinjgdfb_edit" type="text" size="small" icon="el-icon-edit" @click="addOrUpdateHandle(scope.row.id,scope.row)">编辑</el-button>
                <el-button v-if="permissions.jiangjin_jiangjinjgdfb_edit" type="primary" plain size="small">副职得分维护</el-button>
                <!--<el-button v-if="permissions.jiangjin_jiangjinjgdfb_del" type="text" size="small" icon="el-icon-delete" @click="deleteHandle(scope.row.id)">删除</el-button>-->
              </template>
            </el-table-column>
          </el-table>
        </div>

        <div class="avue-crud__pagination">
          <el-pagination
                  @size-change="sizeChangeHandle"
                  @current-change="currentChangeHandle"
                  :current-page="pageIndex"
                  :page-sizes="[15, 25, 50, 100]"
                  :page-size="pageSize"
                  :total="totalPage"
                  background
                  layout="total, sizes, prev, pager, next, jumper">
          </el-pagination>
        </div>
      </div>
      <!-- 弹窗, 新增 / 修改 -->
      <table-form v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></table-form>
    </basic-container>
  </div>
</template>

<script>
  import {fetchList, delObj,getJiangjinJgdfbList} from '@/api/jiangjin/jiangjinjgdfb'
  import TableForm from './jiangjinjgdfb-form'
  import {mapGetters} from 'vuex'
  export default {
    data () {
      return {
        dataForm: {
          year:''
        },
        options: [],
        dataList: [],
        pageIndex: 1,
        pageSize: 15,
        totalPage: 0,
        dataListLoading: false,
        addOrUpdateVisible: false,

      }
    },
    components: {
      TableForm
    },
    created () {
      this.getDataList();

      this.options = [];
      this.options = this.getYearOption;
      this.dataForm.year = this.$moment().format('YYYY');
    },
    computed: {
      ...mapGetters(['permissions']),
      getYearOption(){
        let lResult = [];
        ////console.log(this.$moment().format('YYYY-MM-DD') );
        ////console.log(this.$moment().format('YYYY') );
        let iYear = this.$moment().year();
        for(let i=0;i< 4; i++){
          lResult.push({value: iYear - i, label: iYear - i + '年'});
        }
        return lResult;
      }
    },
    methods: {
      nShowIndex(row, column, cellValue, index){
        return index + 1;
      },
      // 获取数据列表
      getDataList () {
        this.dataListLoading = true
        getJiangjinJgdfbList(this.dataForm).then(res =>{
          this.dataList = res.data.data;
          this.totalPage = res.data.data.length;
        })
        this.dataListLoading = false
      },
      // 原始获取数据列表
      getDataList1 (){
        this.dataListLoading = true
        fetchList(Object.assign({
          current: this.pageIndex,
          size: this.pageSize
        },this.dataForm)).then(response => {
          this.dataList = response.data.data.records
          this.totalPage = response.data.data.total
        })
        this.dataListLoading = false
      },
      // 每页数
      sizeChangeHandle (val) {
        this.pageSize = val
        this.pageIndex = 1
        this.getDataList()
      },
      // 当前页
      currentChangeHandle (val) {
        this.pageIndex = val
        this.getDataList()
      },
      // 新增 / 修改
      addOrUpdateHandle (id,row) {
        //console.log(scope.row);
        let lRow = {};
        lRow = JSON.parse(JSON.stringify(row));
        this.addOrUpdateVisible = true
        this.$nextTick(() => {
          this.$refs.addOrUpdate.init(id,lRow)
        })
      },
      // 删除
      deleteHandle (id) {
        this.$confirm('是否确认删除ID为' + id, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(function () {
          return delObj(id)
        }).then(data => {
          this.$message.closeAll()
          this.$message.success('删除成功')
          this.getDataList()
        })
      },

    }
  }
</script>
